---
title: Deploying LobeChat Database with Docker
description: >-
  Learn how to deploy the LobeChat server database version using Docker on Linux
  and local machines.
tags:
  - LobeChat
  - Docker
  - Database Deployment
  - Postgres
---
# Deploying Server Database Version Using Docker

<div style={{display:"flex", gap: 4}}>
  [![][docker-release-shield]][docker-release-link]

[![][docker-size-shield]][docker-size-link]

[![][docker-pulls-shield]][docker-pulls-link]

</div>

<Callout type="info">
This article assumes that you are familiar with the basic principles and processes of deploying the LobeChat server database version, so it only includes content related to core environment variable configuration. If you are not familiar with the deployment principles of the LobeChat server database version, please refer to [Deploying Server Database](/en/docs/self-hosting/server-database) first.
</Callout>

## Deploying on a Linux Server

Here is the process for deploying the LobeChat server database version on a Linux server:

<Steps>

### Create a Postgres Database Instance

Create a Postgres database instance according to your needs, for example:

```sh
docker run --name my-postgres --network pg -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres
```

<Callout type="warning">
The above command is only for testing/demonstration purposes because this pg instance does not include a persistent part.
</Callout>

The above command will create a PG instance named `my-postgres` on the network `pg`.

### Create a file named `lobe-chat.env` to store environment variables:

```shell
# DB required
KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk=
DATABASE_URL=postgres://postgres:mysecretpassword@my-postgres:5432/postgres

# NEXT_AUTH related
NEXT_AUTH_SECRET=3904039cd41ea1bdf6c93db0db96e250
NEXT_AUTH_SSO_PROVIDERS=auth0
NEXTAUTH_URL=https://your-prod-domain.com/api/auth
AUTH0_CLIENT_ID=xxxxxx
AUTH0_CLIENT_SECRET=cSX_xxxxx
AUTH0_ISSUER=https://lobe-chat-demo.us.auth0.com

# S3 related
S3_ACCESS_KEY_ID=xxxxxxxxxx
S3_SECRET_ACCESS_KEY=xxxxxxxxxx
S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com
S3_BUCKET=lobechat
NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com
```

### Start the lobe-chat-database Docker image

```sh
docker run -it -d -p 3210:3210 --network pg --env-file lobe-chat.env --name lobe-chat-database lobehub/lobe-chat-database
```

If you see the following logs in the container, it means it has started successfully:

```log
[Database] Start to migration...
✅ database migration pass.
-------------------------------------
  ▲ Next.js 14.x.x
  - Local:        http://localhost:3210
  - Network:      http://0.0.0.0:3210

 ✓ Starting...
 ✓ Ready in 95ms
```

</Steps>

<Callout type="tip">
In our official Docker image, the database schema migration is automatically executed before starting the image. We ensure stability from an empty database to all tables being formally available. Therefore, we recommend using an empty table instance for your database to avoid the cost of manually maintaining table structure migration.
</Callout>

## Using Locally (Mac / Windows)

The data version of LobeChat also supports direct use on a local Mac/Windows machine.

Here, we assume that you have a pg instance available on port 5432 locally on your Mac/Windows, with the account `postgres` and password `mysecretpassword`, accessible at `localhost:5432`.

The script command you need to execute is:

```shell
$ docker run -it -d --name lobe-chat-database -p 3210:3210 \
-e DATABASE_URL=postgres://postgres:mysecretpassword@host.docker.internal:5432/postgres \
-e KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk= \
-e NEXT_AUTH_SECRET=3904039cd41ea1bdf6c93db0db96e250 \
-e NEXT_AUTH_SSO_PROVIDERS=auth0 \
-e AUTH0_CLIENT_ID=xxxxxx \
-e AUTH0_CLIENT_SECRET=cSX_xxxxx \
-e AUTH0_ISSUER=https://lobe-chat-demo.us.auth0.com \
-e NEXTAUTH_URL=http://localhost:3210/api/auth \
-e S3_ACCESS_KEY_ID=xxxxxxxxxx \
-e S3_SECRET_ACCESS_KEY=xxxxxxxxxx \
-e S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com \
-e S3_BUCKET=lobechat \
-e NEXT_PUBLIC_S3_DOMAIN=https://s3-for-lobechat.your-domain.com \
lobehub/lobe-chat-database
```

<Callout type="tip">
`Docker` uses a virtual machine solution on `Windows` and `macOS`. If you use `localhost` / `127.0.0.1`, it will refer to the container's `localhost`. In this case, try using `host.docker.internal` instead of `localhost`.
</Callout>

[docker-pulls-link]: https://hub.docker.com/r/lobehub/lobe-chat-database
[docker-pulls-shield]: https://img.shields.io/docker/pulls/lobehub/lobe-chat-database?color=45cc11&labelColor=black&style=flat-square
[docker-release-link]: https://hub.docker.com/r/lobehub/lobe-chat-database
[docker-release-shield]: https://img.shields.io/docker/v/lobehub/lobe-chat-database?color=369eff&label=docker&labelColor=black&logo=docker&logoColor=white&style=flat-square
[docker-size-link]: https://hub.docker.com/r/lobehub/lobe-chat-database
[docker-size-shield]: https://img.shields.io/docker/image-size/lobehub/lobe-chat-database?color=369eff&labelColor=black&style=flat-square
